package com.app.teaware.video;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.app.teaware.R;
import com.app.teaware.basis.BasisActivity;
import com.app.teaware.basis.Constants;
import com.app.teaware.bean.BasisBean;
import com.app.teaware.bean.VideoCatalogListBean;
import com.app.teaware.bean.VideoCatalogListData;
import com.app.teaware.view.RecyclerSpace;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import my.LogUtil;
import my.http.MyHttpListener;
import my.http.MyHttpUtils;
import my.http.MyParams;

/**
 * 警情列表
 */
public class VideoIndexActivity extends BasisActivity {

    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    private MyAdapterList mAdapter;
    private ArrayList<String> mListBean;
    private VideoCatalogListData[] mCatalogAdd;

//    private VideoCatalogListBean mListBeanCatalog;
    private VideoCatalogListData mListBeanCatalogNow;
    private VideoCatalogListBean mListBeanCatalogOrg;
    private VideoCatalogListBean mListBeanChecked;

    @BindView(R.id.recyclerview_catalog)
    RecyclerView recyclerview_catalog;
    private MyAdapterCatalog mAdapterCatelog;


    boolean isSingleModel = false;
    int position_selected = 0;

    boolean isFullScreen = false;

    @BindView(R.id.view_float_back_zone)
    View view_float_back_zone;
    CountDownTimer mTimer;

    @BindView(R.id.btn_catalog_back)
    View btn_catalog_back;

    @SuppressLint("SourceLockedOrientationActivity")
    @Override
    public void initViews() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);//防止键盘弹出
        setContentView(R.layout.video_main_activity);
        mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setTitle("视频监控");
        setTitleLeftButton(null);
        GridLayoutManager layoutManager = new GridLayoutManager(mContext,2);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.addItemDecoration(new RecyclerSpace(1, Color.parseColor("#ffffff")));

        //事件监听
        mRecyclerView.addOnItemTouchListener(new OnRecyclerItemClickListener(mRecyclerView) {

            @Override
            public boolean onItemClick(RecyclerView.ViewHolder vh) {
                return mAdapter.onListitemClick(vh.getAdapterPosition());
            }

            @Override
            public void onItemDoubleClick(RecyclerView.ViewHolder vh) {
                mAdapter.onItemDoubleClick(vh.getAdapterPosition());
            }

            @Override
            public void onItemLongClick(RecyclerView.ViewHolder vh) {

            }
        });


        recyclerview_catalog.setLayoutManager(new LinearLayoutManager(mContext));
        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {

                if (isSingleModel) {
                    return 2;
                }else {
                    return 1;
                }

            }
        });
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        mListBean = new ArrayList<>();
        mListBean.add("");
        mListBean.add("");
        mListBean.add("");
        mListBean.add("");
        mCatalogAdd = new VideoCatalogListData[4];
        setListView();

        setCatalogBackView();
        getCatalog();
        TextView textRight = findViewById(R.id.base_title_right_text);
        textRight.setTextColor(getResources().getColor(R.color.base_text_blue));
        setTitleRightText("全屏", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBtnFullScreen();
            }
        });
        hideFloatBack();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        stopTimer();
    }

    private void setListView() {
        if (mAdapter == null) {
            mAdapter = new MyAdapterList();
            mRecyclerView.setAdapter(mAdapter);
        } else {
            mAdapter.notifyDataSetChanged();
        }
    }


    private void getCatalog(){
        MyParams params = new MyParams();
        showProgress();
//        params.put("showAll", "false");
        MyHttpUtils.post(Constants.URL_VIDEO_GET_CATALOG, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        mListBeanCatalogOrg = (VideoCatalogListBean) result;
                        mListBeanCatalogOrg.processList();
                        mListBeanCatalogNow = new VideoCatalogListData();
                        mListBeanCatalogNow.setChildren(mListBeanCatalogOrg.getList());
                        setListViewCatalog();
                        setCatalogBackView();
//                        mListBeanOrg.save();
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);
//            mListBean = new ServiceNewListBean();
                        setListView();
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        hideLoading();
                    }
                },
                0, VideoCatalogListBean.class,120);
    }

    void setListViewCatalog(){
        mAdapterCatelog = new MyAdapterCatalog();
        recyclerview_catalog.setAdapter(mAdapterCatelog);
    }


    @SuppressLint("SourceLockedOrientationActivity")
    @OnClick(R.id.btn_fullscreen)
    void onBtnFullScreen(){

        Configuration mConfiguration = this.getResources().getConfiguration(); //获取设置的配置信息
        int ori = mConfiguration.orientation; //获取屏幕方向
        if (ori == mConfiguration.ORIENTATION_LANDSCAPE) {

            isFullScreen =false;
            mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        } else if (ori == mConfiguration.ORIENTATION_PORTRAIT) {
            isFullScreen =true;
            mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }

    }
    void setFullScreenView(){
//        ViewGroup.LayoutParams layoutParams = frameLayout.getLayoutParams();
        Configuration mConfiguration = this.getResources().getConfiguration(); //获取设置的配置信息
        int ori = mConfiguration.orientation; //获取屏幕方向
        if (ori == mConfiguration.ORIENTATION_LANDSCAPE) {
            hideSystemUI();
            findViewById(R.id.base_title_root).setVisibility(View.GONE);
            findViewById(R.id.view_bottom_zone).setVisibility(View.GONE);
            showFloatBack();
        } else if (ori == mConfiguration.ORIENTATION_PORTRAIT) {
            showSystemUI();
            findViewById(R.id.base_title_root).setVisibility(View.VISIBLE);
            findViewById(R.id.view_bottom_zone).setVisibility(View.VISIBLE);
            setTitleStatusZone();
            hideFloatBack();
        }
//        mRecyclerView.notify();
        if(isSingleModel){
//            mAdapter.notifyItemChanged(0,MyAdapterList.PAYLOAD_VIEW);
            for(int i = 0; i < 4; i ++){
                mAdapter.notifyItemChanged(i,MyAdapterList.PAYLOAD_VIEW);
            }
        }else {
            for(int i = 0; i < 4; i ++){
                mAdapter.notifyItemChanged(i,MyAdapterList.PAYLOAD_VIEW);
            }
        }
//        mAdapter.notifyDataSetChanged();
    }


    void showFloatBack(){
        if(view_float_back_zone.getVisibility() == View.GONE){
            TranslateAnimation showAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
            showAnim.setDuration(500);
            view_float_back_zone.startAnimation(showAnim);
            view_float_back_zone.setVisibility(View.VISIBLE);
        }
        stopTimer();
        startTimer();
    }
    void hideFloatBack(){
        if(view_float_back_zone.getVisibility() == View.VISIBLE){
            TranslateAnimation hideAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
            hideAnim.setDuration(500);
            view_float_back_zone.startAnimation(hideAnim);
            hideAnim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    view_float_back_zone.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
        }
//        view_float_back_zone.setVisibility(View.GONE);
        stopTimer();
    }
    void stopTimer(){
        if(mTimer != null){
            mTimer.cancel();
            mTimer = null;
        }
    }
    void startTimer(){
        if(mTimer != null){
            stopTimer();
        }
        mTimer = new CountDownTimer(3000,1000) {
            @Override
            public void onTick(long millisUntilFinished) {
            }
            @Override
            public void onFinish() {
                hideFloatBack();
            }
        };
        mTimer.start();
    }

//    @SuppressLint("SourceLockedOrientationActivity")
//    @OnClick(R.id.btn_fullscreen)
//    void onFloatBackClick(){
//        isFullScreen = false;
//        mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        LogUtil.i("onConfigurationChanged------->");
        setFullScreenView();
    }

    void onCatalogLeafClick(VideoCatalogListData data){
        if(!data.isVideo_BOOLEAN())return;
        if(!data.isOnline_BOOLEAN())return;
        if(mCatalogAdd[position_selected] != null && mCatalogAdd[position_selected] .getId().equals(data.getId())){
            return;
        }
        mCatalogAdd[position_selected] = data;
        getPlayUrl(data);
        mAdapterCatelog.notifyDataSetChanged();
    }
    boolean isDataAdd(VideoCatalogListData data){
        for(VideoCatalogListData item:mCatalogAdd){
            if(item != null && data.getId().equals(item.getId())){
                return true;
            }
        }
        return false;
    }

    void getPlayUrl(VideoCatalogListData data){
        MyParams params = new MyParams();
        showProgress();
        params.put("cameraIndexCode", data.getId());
        params.put("protocol", "rtsp");
        MyHttpUtils.post(Constants.URL_VIDEO_GET_PLAY_URL, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        BasisBean basisBean = (BasisBean) result;
                        mListBean.set(position_selected,basisBean.getResultData());
                        Bundle bundle = new Bundle();
                        bundle.putString("url",basisBean.getResultData());
//                        ActivityTool.skipActivity(mContext,HKVideoDetailActivity.class,bundle);
                        if(isSingleModel){
                            mAdapter.notifyItemChanged(position_selected);
                        }else {
                            mAdapter.notifyItemChanged(position_selected);
                        }
                        if( !isSingleModel && position_selected < (mListBean.size()-1) && mCatalogAdd[position_selected+1] == null ){
                            position_selected = position_selected+1;
                            mAdapter.notifyItemChanged(position_selected-1,MyAdapterList.PAYLOAD_SELETED);
                            mAdapter.notifyItemChanged(position_selected,MyAdapterList.PAYLOAD_SELETED);
                        }
//                        mAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        hideLoading();
                    }
                },
                0, BasisBean.class);
    }


    public class MyAdapterList extends RecyclerView.Adapter<MyAdapterList.ViewHolder> {

        public MyAdapterList() {

        }

        public boolean onListitemClick(int position) {
//                int position = (int) view.getTag();
            if(isFullScreen){
                showFloatBack();
            }
//            showFloatBack();
            if (isSingleModel) return false;
            if(position_selected == position)return false;
            int oldpossition = position_selected;
            position_selected = position;
//            mAdapter.notifyDataSetChanged();
            mAdapter.notifyItemChanged(oldpossition, PAYLOAD_SELETED);
            mAdapter.notifyItemChanged(position, PAYLOAD_SELETED);

            return true;
        }

        public void onItemDoubleClick(int position) {
            LogUtil.i("onItemDoubleClick---------->");
            if (isSingleModel) {
                isSingleModel = false;
            } else {
                isSingleModel = true;
            }

            for(int i = 0; i < 4; i ++){
                mAdapter.notifyItemChanged(i,MyAdapterList.PAYLOAD_VIEW);
            }
//            mAdapter.notifyItemChanged(position,PAYLOAD_VIEW);
//            mAdapter.notifyDataSetChanged();
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.video_list_item, viewGroup, false);
            return new ViewHolder(view);
        }


//        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
//            viewHolder.bind(position);
        }

        public static final int PAYLOAD_SELETED = 0,PAYLOAD_PLAY = 1,PAYLOAD_VIEW = 2;

        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull List<Object> payloads) {
            super.onBindViewHolder(holder, position, payloads);
            if (payloads.isEmpty()) {//payloads为空 即不是调用notifyItemChanged(position,payloads)方法执行的
                //在这里进行初始化item全部控件
                holder.bind(position);
            } else {//payloads不为空 即调用notifyItemChanged(position,payloads)方法后执行的

                //在这里可以获取payloads中的数据  进行局部刷新
                //假设是int类型

                int type = (int) payloads.get(0);// 刷新哪个部分 标志位
                switch (type) {
                    case PAYLOAD_SELETED:
                        if (isSingleModel) {
                            holder.videoView.setSeleteView(true);
                        } else {
                            holder.videoView.setSeleteView(position == position_selected);
                        }
                        break;
                    case PAYLOAD_VIEW:
//                        holder.videoView.invalidate();
                        holder.videoView.setParams(isSingleModel,isFullScreen);
                        holder.videoView.setSeleteView(position == position_selected);
//                        holder.videoView.setParams(position == position_selected,isFullScreen);
                        if(isSingleModel){
                            holder.list_item.setVisibility(position == position_selected?View.VISIBLE:View.GONE);
                        }else {
                            holder.list_item.setVisibility(View.VISIBLE);
                        }
                        break;

                }
            }
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
//            if(isSingleModel)return 1;
            return mListBean == null ? 0 : mListBean.size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.custom_videoview)
            public CustomVideo videoView;


            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }

            public void bind(int position) {
                String url;
//                videoView.setBig(isSingleModel);
//                videoView.setFullSreen(isFullScreen);
//                videoView.setParams(position == position_selected,isFullScreen);
                videoView.setParams(isSingleModel,isFullScreen);
                url = mListBean.get(position);
                videoView.setData(url,position == position_selected);
//                if(isSingleModel){
//                    url = mListBean.get(position_selected);
//                    videoView.setData(url,true);
//                }else {
//                    url = mListBean.get(position);
//                    videoView.setData(url,position == position_selected);
//                }

                list_item.setTag(position);
            }

        }
    }

    @OnClick(R.id.btn_catalog_back)
    void onCatalogBackClick(){
        if(mListBeanCatalogNow == null || TextUtils.isEmpty(mListBeanCatalogNow.getParentId()))return;
        mListBeanCatalogNow = mListBeanCatalogOrg.getItemById(mListBeanCatalogNow.getParentId());
        mAdapterCatelog.notifyDataSetChanged();
        setCatalogBackView();
    }
    void setCatalogBackView(){
        if(mListBeanCatalogNow == null || TextUtils.isEmpty(mListBeanCatalogNow.getParentId())){
            btn_catalog_back.setVisibility(View.GONE);
        }else {
            btn_catalog_back.setVisibility(View.VISIBLE);
        }
    }


    public class MyAdapterCatalog extends RecyclerView.Adapter<MyAdapterCatalog.ViewHolder> {

        public MyAdapterCatalog() {

        }

        //创建新View，被LayoutManager所调用
        @Override
        public MyAdapterCatalog.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.video_catalog_list_item, viewGroup, false);
            return new MyAdapterCatalog.ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(MyAdapterCatalog.ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return mListBeanCatalogNow == null ? 0 : mListBeanCatalogNow.getChildren().size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.img_icon)
            public ImageView img_icon;
            @BindView(R.id.img_arrow)
            public ImageView img_arrow;
            @BindView(R.id.text_name)
            public TextView text_name;
            @BindView(R.id.text_online)
            public TextView text_online;
            @BindView(R.id.text_offline)
            public TextView text_offline;
            @BindView(R.id.text_num)
            public TextView text_num;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);

            }

            public void bind(int position) {
                VideoCatalogListData data = mListBeanCatalogNow.getChildren().get(position);

                text_name.setText(data.getName());
                img_icon.setVisibility(data.isVideo_BOOLEAN()?View.VISIBLE:View.GONE);
                img_arrow.setVisibility(data.isVideo_BOOLEAN()?View.GONE:View.VISIBLE);
                if(data.isVideo_BOOLEAN()){
                    if(isDataAdd(data)){
                        img_icon.setImageResource(R.drawable.video_icon_video_blue);
                    }else {
                        img_icon.setImageResource(R.drawable.video_icon_video_grey);
                    }
                    text_online.setVisibility(data.isOnline_BOOLEAN()?View.VISIBLE:View.GONE);
                    text_offline.setVisibility(!data.isOnline_BOOLEAN()?View.VISIBLE:View.GONE);

                    if(data.isOnline_BOOLEAN()){
                        text_name.setTextColor(Color.parseColor("#252B32"));
                    }else {
                        text_name.setTextColor(Color.parseColor("#75000000"));
                    }

                    text_num.setVisibility(View.GONE);
                }else {
                    text_name.setTextColor(Color.parseColor("#252B32"));
                    text_online.setVisibility(View.GONE);
                    text_offline.setVisibility(View.GONE);

                    text_num.setVisibility(View.VISIBLE);

                    text_num.setText(data.getOnlineCount() +"/"+data.getTotalCount());
                }
                list_item.setTag(position);
            }

            @OnClick(R.id.list_item)
            void onItemClick(View view){
                int position = (int) view.getTag();
                VideoCatalogListData itemData = mListBeanCatalogNow.getChildren().get(position);
                if(itemData.isVideo_BOOLEAN()){
                    onCatalogLeafClick(itemData);
                }else {
                    if(itemData.getChildren() == null || itemData.getChildren().size() == 0){
                        showToast("没有下一级了");
                    }else {
                        mListBeanCatalogNow = itemData;
                        notifyDataSetChanged();
                        setCatalogBackView();
                    }
                }
            }
        }
    }

    /**
     * 隐藏系统ui
     */
    private void hideSystemUI() {
        //隐藏ActionBar 如果使用了NoActionBar的Theme则不需要隐藏actionBar
//        ActionBar actionBar = getSupportActionBar();
//        if (actionBar != null) {
//            actionBar.hide();
//        }

        //TODO：View.setSystemUiVisibility(int visibility)中，visibility是Mode与Layout任意取值的组合，可传入的实参为：

        // Mode属性
        //View.SYSTEM_UI_FLAG_LOW_PROFILE：状态栏显示处于低能显示状态(low profile模式)，状态栏上一些图标显示会被隐藏。
        //View.SYSTEM_UI_FLAG_FULLSCREEN：Activity全屏显示，且状态栏被隐藏覆盖掉。等同于（WindowManager.LayoutParams.FLAG_FULLSCREEN）
        //View.SYSTEM_UI_FLAG_HIDE_NAVIGATION：隐藏虚拟按键(导航栏)。有些手机会用虚拟按键来代替物理按键。
        //View.SYSTEM_UI_FLAG_IMMERSIVE：这个flag只有当设置了SYSTEM_UI_FLAG_HIDE_NAVIGATION才起作用。
        // 如果没有设置这个flag，任意的View相互动作都退出SYSTEM_UI_FLAG_HIDE_NAVIGATION模式。如果设置就不会退出。
        //View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY：这个flag只有当设置了SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION 时才起作用。
        // 如果没有设置这个flag，任意的View相互动作都坏退出SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION模式。如果设置就不受影响。

        // Layout属性
        //View.SYSTEM_UI_FLAG_LAYOUT_STABLE： 保持View Layout不变，隐藏状态栏或者导航栏后，View不会拉伸。
        //View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN：让View全屏显示，Layout会被拉伸到StatusBar下面，不包含NavigationBar。
        //View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION：让View全屏显示，Layout会被拉伸到StatusBar和NavigationBar下面。
        View decorView = getWindow().getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LOW_PROFILE
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            );
        }
        //解决在华为手机上横屏时，状态栏不消失的问题
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏状态栏

    }

    /**
     * 显示系统UI
     */
    private void showSystemUI() {
        //显示ActionBar 如果使用了NoActionBar的Theme则不需要显示actionBar
//        ActionBar actionBar = getSupportActionBar();
//        if (actionBar != null) {
//            actionBar.show();
//        }
        View decorView = getWindow().getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            // This snippet shows the system bars. It does this by removing all the flags
            // except for the ones that make the content appear under the system bars.
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        }
        //解决在华为手机上横屏时，状态栏不消失的问题
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //显示状态栏
    }

}
